########################################################################
# R-code:	CASA_FTIP_Vario.R
# Purpose:	For fitting variogram model paramteters with 'Run_vario.R',
# 			and kriging with 'Run_krige.r'.
#			Based upon anomalies of Central America/South America
#			FTIP satelitte data (extracted at rainfall station locations).
########################################################################

############################
# LOAD REQUIRED 'R' PACKAGES

#help(available.packages)
#search()	#Lists currently loaded packages

#Might help with installing 'rgdal' or its dependency 'proj4'
#setRepositories(ind=1:2) 

#install.packages("sp", repos="http://cran.us.r-project.org")#
#install.packages("zoo", repos="http://cran.us.r-project.org")#
#install.packages("xts", repos="http://cran.us.r-project.org")#
#install.packages("spacetime", repos="http://cran.us.r-project.org")#
#install.packages("gstat", repos="http://cran.us.r-project.org")#
#install.packages("proj4", repos="http://cran.us.r-project.org")
#install.packages("rgdal", repos="http://cran.us.r-project.org")
#install.packages("raster", repos="http://cran.us.r-project.org")
#install.packages("geoR", repos="http://cran.us.r-project.org")
#install.packages("MASS", repos="http://cran.us.r-project.org")
#install.packages("maps", repos="http://cran.us.r-project.org")
#install.packages("maptools", repos="http://cran.us.r-project.org")
#install.packages("splancs", repos="http://cran.us.r-project.org")
#install.packages("RandomFields", repos="http://cran.us.r-project.org")
#install.packages("geoR", repos="http://cran.us.r-project.org")
#install.packages("RColorBrewer", repos="http://cran.us.r-project.org")


library (sp)        	# sp        Depends: R (= 2.10.0), methods, graphics                   
library (zoo)       	# zoo       Depends: R (= 2.10.0), stats                      
library (xts)       	# xts       Depends: zoo (= 1.7-2)                    
library (spacetime) 	# spacetime Depends: R (= 2.10.0), methods, sp (= 0.9-89), zoo, xts                          
library (gstat)    	 	# gstat     Depends: R (= 2.10), methods, sp (= 0.9-72), spacetime (= 0.4-4) 
library (proj4)     	# proj4                        
library (rgdal)     	# rgdal     Depends: R (= 2.10.0), methods, sp (= 0.9-60)                        
library (raster)    	# raster    Depends: methods, sp, R (= 2.11.0) 
library (geoR)   		# geoR
library (MASS)   		# MASS
library (maps)  		# maps
library (maptools) 		# maptools
library (splancs)		# splancs
library (RandomFields)	# RandomFields
library (geoR)			# geoR
library (RColorBrewer)  # RColorBrewer

#######
# PATHS
#
# Note that subdirectories require different slashes per operating system
# (i.e. "/" for Unix, "\\" for Windows)

DirPrecipSourceVgmKrg	=	"C:\\Users\\bo_romero\\git\\fews-02-casa\\fews-02-casa\\CODE\\"

DirRefData				=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\FCLIM_p25_w-Oceans\\"

DirLandMask				=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\DATA\\LandMasks\\"


DirPrecipVgmPar			=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\RESULTS\\Precip\\Variogram_Parameters\\"
DirPrecipData			=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\DATA\\Precip\\2012-05-02\\"
DirPrecipMeta			=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\DATA\\Precip\\2012-05-02\\"
DirPrecipKrige			=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\RESULTS\\Precip\\"	# Note that subdirectories will be created for months
DirPrecipMosaic			=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\RESULTS\\Precip\\"	# Note that subdirectories will be used for months
DirPrecipMosaicMask		=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\RESULTS\\Precip\\"	# Note that subdirectories will be used for months

DirTempVgmPar			=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\RESULTS\\Temp\\Variogram_Parameters\\"
DirTempData				=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\DATA\\Temp\\2012-05-02\\"
DirTempMeta				=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\DATA\\Temp\\2012-05-02\\"
DirTempKrige			=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\RESULTS\\Temp\\"	# Note that subdirectories will be created for months
DirTempMosaic			=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\RESULTS\\Temp\\"	# Note that subdirectories will be used for months
DirTempMosaicMask		=	"C:\\Users\\bo_romero\\git\\fews-01-global-eval\\Global_Eval\\RESULTS\\Temp\\"	# Note that subdirectories will be used for months




FilePrecipSourceVgmKrg		=	"vario_krige.r"

FilePrecipVgmPar			=	"Variogram_Parameters.csv"	# Could use list.files for many files, but would need to update dependent code.
FileTempVgmPar				=	"Variogram_Parameters.csv"	# Could use list.files for many files, but would need to update dependent code.

FilePrefixPrecipRefData		=	"p25.FCLIM_5050_wOceans."
FileSuffixPrecipRefData		=	".tif"

FileLandMask				=	"global_landmask.50N50S.p25Deg.tif"

FilePrefixPrecipData		=	"precp"
FileSuffixPrecipData		=	"data.csv"
FilePrefixPrecipMeta		=	"precp"
FileSuffixPrecipMeta		=	"meta.csv"

FilePrefixPrecipKrgEstMm	=	"krmm"
FilePrefixPrecipKrgErrMm	=	"semm"
FilePrefixPrecipKrgEstPc	=	"krpc"
FilePrefixPrecipKrgErrPc	=	"sepc"
FileSuffixPrecipKrgImg		=	".bil"
FileSuffixPrecipKrgHdr		=	".hdr"

FilePrefixTempData			=	"temp"
FileSuffixTempData			=	"data.csv"
FilePrefixTempMeta			=	"temp"
FileSuffixTempMeta			=	"meta.csv"

FilePrefixTempKrgEstDg		=	"krdeg"
FilePrefixTempKrgErrDg		=	"sedeg"
FileSuffixTempKrgImg		=	".bil"
FileSuffixTempKrgHdr		=	".hdr"



##################
# GLOBAL VARIABLES
